package com.lishao.soccer.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lishao.soccer.bean.entity.SmUser;
import com.lishao.soccer.bean.entity.TmMember;
import com.lishao.soccer.bean.entity.TmScoreList;
import com.lishao.soccer.dao.TmMemberMapper;
import com.lishao.soccer.dao.TmScoreListMapper;
import com.lishao.soccer.service.TmMemberService;

public class TmMemberServiceImpl implements TmMemberService {
	TmMemberMapper tmMemberMapper;
	TmScoreListMapper tmScoreListMapper;

	//评分榜
	public List<TmMember> selectTechScore(Long teamId,Long tmGameId,Date startDate,Date endDate){
		Map paraMap = new HashMap();
		paraMap.put("teamId", teamId);paraMap.put("tmGameId", tmGameId);
		paraMap.put("startDate", startDate);paraMap.put("endDate", endDate);
		List<TmMember> techScoreList = tmMemberMapper.selectTechScore(paraMap);
		return techScoreList;
	}
	public List<TmMember> selectTechScore(Long tmScoreListId){
		TmScoreList tmScoreList = tmScoreListMapper.selectByPrimaryKey(tmScoreListId);
		return selectTechScore(tmScoreList.getTeamId(), null, tmScoreList.getStartDate(), tmScoreList.getEndDate());
	}
	//进球榜
	public List<TmMember> selectScoreList(Long teamId,Long tmGameId,Date startDate,Date endDate){
		Map paraMap = new HashMap();
		paraMap.put("itemId", 1);
		paraMap.put("teamId", teamId);paraMap.put("tmGameId", tmGameId);
		paraMap.put("startDate", startDate);paraMap.put("endDate", endDate);
		List<TmMember> scoreList = tmMemberMapper.selectScoreAssistList(paraMap);
		return scoreList;
	}
	public List<TmMember> selectScoreList(Long tmScoreListId){
		TmScoreList tmScoreList = tmScoreListMapper.selectByPrimaryKey(tmScoreListId);
		return selectScoreList(tmScoreList.getTeamId(), null, tmScoreList.getStartDate(), tmScoreList.getEndDate());
	}
	//助攻榜
	public List<TmMember> selectAssistList(Long teamId,Long tmGameId,Date startDate,Date endDate){
		Map paraMap = new HashMap();
		paraMap.put("itemId", 2);
		paraMap.put("teamId", teamId);paraMap.put("tmGameId", tmGameId);
		paraMap.put("startDate", startDate);paraMap.put("endDate", endDate);
		List<TmMember> assistList = tmMemberMapper.selectScoreAssistList(paraMap);
		return assistList;
	}
	public List<TmMember> selectAssistList(Long tmScoreListId){
		TmScoreList tmScoreList = tmScoreListMapper.selectByPrimaryKey(tmScoreListId);
		return selectAssistList(tmScoreList.getTeamId(), null, tmScoreList.getStartDate(), tmScoreList.getEndDate());
	}
	//违规榜
    public List<TmMember> selectDisciplineList(Long teamId,Long tmGameId,Date startDate,Date endDate){
    	Map paraMap = new HashMap();
		paraMap.put("teamId", teamId);paraMap.put("tmGameId", tmGameId);
		paraMap.put("startDate", startDate);paraMap.put("endDate", endDate);
		List<TmMember> disciplineList = tmMemberMapper.selectDisciplineList(paraMap);
		return disciplineList;
    }
    public List<TmMember> selectDisciplineList(Long tmScoreListId){
		TmScoreList tmScoreList = tmScoreListMapper.selectByPrimaryKey(tmScoreListId);
		return selectDisciplineList(tmScoreList.getTeamId(), null, tmScoreList.getStartDate(), tmScoreList.getEndDate());
	}
    public List<TmMember> selectArriveGameProportionList(Long teamId,Long tmGameId,Date startDate,Date endDate){
    	Map paraMap = new HashMap();
		paraMap.put("teamId", teamId);paraMap.put("tmGameId", tmGameId);
		paraMap.put("startDate", startDate);paraMap.put("endDate", endDate);
		List<TmMember> arriveGameProportionList = tmMemberMapper.selectArriveGameProportionList(paraMap);
		return arriveGameProportionList;
    }
	public List<TmMember> selectArriveGameProportionList(Long tmScoreListId){
		TmScoreList tmScoreList = tmScoreListMapper.selectByPrimaryKey(tmScoreListId);
		return selectArriveGameProportionList(tmScoreList.getTeamId(), null, tmScoreList.getStartDate(), tmScoreList.getEndDate());
	}
    public TmMember selectByTeamUser(Long teamId,SmUser smUser){
    	Map paraMap = new HashMap();paraMap.put("teamId", teamId);paraMap.put("logUserId", smUser.getRowId());
    	List<TmMember> tmMemberList = tmMemberMapper.selectByTeamUser(paraMap);
    	return tmMemberList==null?null:tmMemberList.get(0);
    }
    public List<TmMember> selectByTeam(Long teamId){
    	Map paraMap = new HashMap();paraMap.put("teamId", teamId);
    	List<TmMember> tmMemberList = tmMemberMapper.selectByTeamUser(paraMap);
    	return tmMemberList;
    }
    public boolean getManageFlag(Long teamId,Long userId){
    	boolean bResult=false;
    	Map paraMap = new HashMap();
    	paraMap.put("teamId", teamId);
    	paraMap.put("logUserId", userId);
    	List<TmMember> tmMemberList = tmMemberMapper.selectByTeamUser(paraMap);
    	if(tmMemberList!=null&&tmMemberList.size()>0){
    		TmMember tmMember = tmMemberList.get(0);
    		if("1".equals(tmMember.getManageFlag())){
    			bResult=true;
    		}
    	}
    	return bResult;
    }
	//get set
	public TmMemberMapper getTmMemberMapper() {
		return tmMemberMapper;
	}

	public void setTmMemberMapper(TmMemberMapper tmMemberMapper) {
		this.tmMemberMapper = tmMemberMapper;
	}

	public TmScoreListMapper getTmScoreListMapper() {
		return tmScoreListMapper;
	}

	public void setTmScoreListMapper(TmScoreListMapper tmScoreListMapper) {
		this.tmScoreListMapper = tmScoreListMapper;
	}
	
}
